
<template>
  <a-card :bordered="false" :bodyStyle="{ padding: '16px', height: '100%' }">
    <div class="table-page-search-wrapper" style="padding-left:10px;padding-right:10px;">
      <a-form layout="inline">
        <a-row :gutter="48">
          <a-col :md="6" :sm="24">
            <a-form-item label="搜索物品">
              <a-input
                v-model="keywords"
                placeholder="请输入物品名称(回车搜索)"
                @pressEnter="$refs.table.refresh(true)"
              >
                <a-tooltip slot="suffix" title="请输入物品名称">
                  <a-icon
                    type="search"
                    style="color: rgba(0,0,0,.45)"
                    @click="$refs.table.refresh(true)"
                  />
                </a-tooltip>
              </a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="启用状态">
              <!-- <a-radio-group v-model="queryParam.is_enable">
                <a-radio :value="1">启用</a-radio>
                <a-radio :value="2">停用</a-radio>
              </a-radio-group>-->
              <a-checkbox @change="openEnable" :checked="openChecked">启用</a-checkbox>
              <a-checkbox @change="closeEnable" :checked="closeChecked">停用</a-checkbox>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="库存状况">
              <!-- <a-radio :value="1" v-model="queryParam.type">库存不足</a-radio> -->
              <a-checkbox @change="changeSearchType" v-model="isStock">库存不足</a-checkbox>
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <div class="table-operator">
      <a-button type="primary" style="margin-right:20px;" @click="visibles=true">新建物品</a-button>
    </div>
    <!-- <a-alert type="warning" message="物品的售卖详情可在“财务-收据明细”中查看" banner class="expand_warning" /> -->
    <s-table
      :columns="columns"
      :data="loadData"
      :rowKey="(record) => record.id"
      class="user_management_table"
      style="margin-top:20px;"
      ref="table"
      :pagination="pagination"
    >
      <span slot="is_enable" slot-scope="text,record">
        <a-switch :checked="text==1?true:false" @click="changeType(text,record)" />
      </span>
      <span slot="stock" slot-scope="text,record">
        <span v-if="record.surplus_stock>record.stock">{{text}}</span>
        <span v-else style="color:red;">{{text}}</span>
      </span>
      <span slot="course" slot-scope="text, record">
        <span v-if="record.type==2">
          <span v-if="record.course_arr.length>0">
            <span v-for="(item,index) in record.course_arr" :key="index">
              <span>{{item.name}}</span>
              <span v-if="index< record.course_arr.length-1">，</span>
            </span>
          </span>
          <span v-else>--</span>
        </span>
        <span v-else-if="record.type==1">全部课程</span>
        <span v-else>未绑定</span>
      </span>
      <span slot="action" slot-scope="text, record">
        <template>
          <a @click="showAddNumModel(record)">增加库存</a>
          <a-divider type="vertical" />
          <a @click="showStock(record)">库存变更记录</a>
          <a-divider type="vertical" />
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="del(record)">删除</a>
        </template>
      </span>
    </s-table>
    <create-form ref="createModal" @ok="handleOk" />
    <!-- <step-by-step-modal ref="modal" @ok="handleOk" /> -->

    <!-- 新建 -->
    <a-modal
      title="新建物品"
      :width="640"
      :visible="visibles"
      :confirmLoading="confirmLoading"
      @ok="modelSubmit('ruleForm')"
      :footer="null"
      @cancel="modelCancel"
      :destroyOnClose="true"
      :keyboard="false"
      :zIndex="999"
      :bodyStyle="{padding:0}"
    >
      <a-spin :spinning="confirmLoading">
        <a-form-model
          ref="ruleForm"
          :model="ruleForm"
          :rules="rules"
          v-bind="layout"
          style="padding:24px;"
        >
          <a-form-model-item has-feedback label="物品名称" prop="name">
            <a-input
              v-model="ruleForm.name"
              style="width:250px"
              autocomplete="off"
              placeholder="请输入物品名称，如“书本”"
            />
          </a-form-model-item>
          <a-form-model-item label="售卖单价" prop="unit_price">
            <a-input-number
              :min="0"
              :step="0.01"
              v-model="ruleForm.unit_price"
              style="width:150px"
              placeholder="请输入售卖单价"
            />&nbsp;元
          </a-form-model-item>
          <a-form-model-item label="库存预警数量" prop="stock">
            <a-input-number
              :min="0"
              :max="9999999999"
              :step="0"
              v-model="ruleForm.stock"
              style="width:150px"
              placeholder="请输入"
            />
          </a-form-model-item>
          <a-form-model-item label="绑定课程">
            <a-radio-group name="radioGroup" v-model="ruleForm.type" :default-value="1">
              <a-radio :value="0">不绑定课程</a-radio>
              <a-radio :value="1">绑定全部课程</a-radio>
              <a-radio :value="2">绑定部分课程</a-radio>
            </a-radio-group>
            <div v-if="ruleForm.type==2">
              <a @click="showComponents('add')">添加课程</a>
              <div
                v-if="ruleForm.course_arr!==''"
                style="width:320px;overflow: hidden;text-overflow: ellipsis;white-space:nowrap;"
              >
                <span v-for="(item,index) in ruleForm.course_arr" :key="index">
                  <span>{{item.name}}</span>
                  <span v-if="index<ruleForm.course_arr.length-1">,</span>
                </span>
              </div>
            </div>
          </a-form-model-item>
        </a-form-model>
        <div
          class="bottom"
          style="border-top:1px solid #e8e8e8;padding:12px 24px;text-align:right;"
        >
          <a-button type="primary" style="margin-right:10px;" @click="modelSubmit('ruleForm',1)">完成</a-button>
          <a-button type="primary" @click="modelSubmit('ruleForm',2)">完成并增加库存</a-button>
        </div>
      </a-spin>
    </a-modal>

    <!-- 编辑 -->
    <a-modal
      title="编辑"
      :width="640"
      :visible="visiblesEdit"
      :confirmLoading="confirmLoading"
      @ok="modelEditSubmit('ruleFormEdit')"
      @cancel="modelEditCancel"
      :destroyOnClose="true"
      :keyboard="false"
      :zIndex="999"
    >
      <a-spin :spinning="confirmLoading">
        <a-form-model ref="ruleFormEdit" :model="ruleFormEdit" :rules="rules" v-bind="layout">
          <a-form-model-item has-feedback label="物品名称" prop="name">
            <a-input
              v-model="ruleFormEdit.name"
              style="width:250px;"
              autocomplete="off"
              placeholder="请输入费用名称，如“考试费”"
            />
          </a-form-model-item>
          <a-form-model-item label="售卖单价" prop="unit_price">
            <a-input-number
              :min="0"
              :step="0.01"
              v-model="ruleFormEdit.unit_price"
              style="width:150px"
              placeholder="请输入售卖单价"
            />&nbsp;元
          </a-form-model-item>
          <a-form-model-item label="库存预警数量" prop="stock">
            <a-input-number
              :min="0"
              :step="0"
              :max="9999999999"
              v-model="ruleFormEdit.stock"
              style="width:150px"
              placeholder="请输入"
            />
          </a-form-model-item>
          <!-- <a-form-model-item label="绑定课程">
            <a @click="showComponents('edit')">添加课程</a>
            <div
              v-if="ruleFormEdit.course_arr!==''"
              style="width:320px;overflow: hidden;text-overflow: ellipsis;white-space:nowrap;"
            >
              <span v-for="(item,index) in ruleFormEdit.course_arr" :key="index">
                <span>{{item.name}}</span>
                <span v-if="index<ruleFormEdit.course_arr.length-1">,</span>
              </span>
            </div>
          </a-form-model-item>-->
          <a-form-model-item label="绑定课程">
            <a-radio-group name="radioGroup" v-model="ruleFormEdit.type" :default-value="1">
              <a-radio :value="0">不绑定课程</a-radio>
              <a-radio :value="1">绑定全部课程</a-radio>
              <a-radio :value="2">绑定部分课程</a-radio>
            </a-radio-group>
            <div v-if="ruleFormEdit.type==2">
              <a @click="showComponents('edit')">添加课程</a>
              <div
                v-if="ruleFormEdit.course_arr!==''"
                style="width:320px;overflow: hidden;text-overflow: ellipsis;white-space:nowrap;"
              >
                <span v-for="(item,index) in ruleFormEdit.course_arr" :key="index">
                  <span>{{item.name}}</span>
                  <span v-if="index<ruleFormEdit.course_arr.length-1">,</span>
                </span>
              </div>
            </div>
          </a-form-model-item>
        </a-form-model>
      </a-spin>
    </a-modal>
    <course-model ref="course" @receive="receiveData"></course-model>
    <!-- :msg="sendChildData" -->
    <a-modal
      title="增加库存"
      :width="640"
      :visible="addNumVisible"
      :confirmLoading="addNumLoading"
      @ok="addNumSubmit('addNum')"
      @cancel="addNumVisible= false"
      :destroyOnClose="true"
      :zIndex="999"
    >
      <a-spin :spinning="confirmLoading">
        <a-form-model ref="addNum" :model="addNumForm" :rules="addNumRule" v-bind="layout">
          <a-form-model-item has-feedback label="物品名称" prop="goods_name">{{addNumForm.goods_name}}</a-form-model-item>
          <a-form-model-item label="采购日期" prop="purchase_at">
            <a-date-picker v-model="addNumForm.purchase_at" :allowClear="false" />
          </a-form-model-item>
          <a-form-model-item label="经办人" prop="operator">
            <a-input placeholder="请输入经办人" v-model="addNumForm.operator" style="width:300px;" />
          </a-form-model-item>
          <a-form-model-item label="采购单价" prop="unit_price">
            <a-input-number
              :min="0"
              :step="0.01"
              v-model="addNumForm.unit_price"
              style="width:150px"
              placeholder="请输入采购单价 "
              @change="countForm('unit')"
            />元
          </a-form-model-item>

          <a-form-model-item label="采购数量" prop="number">
            <a-input-number
              :min="1"
              :max="9999999999"
              :step="1"
              v-model="addNumForm.number"
              style="width:150px"
              placeholder="请输入采购数量"
              @change="countForm('num')"
            />
          </a-form-model-item>
          <a-form-model-item label="采购总价" prop="total_price">
            <a-input-number
              :min="0"
              :step="0.01"
              v-model="addNumForm.total_price"
              style="width:150px"
              placeholder="请输入 "
              @change="countForm('total')"
            />元
          </a-form-model-item>
          <a-form-model-item label="采购备注">
            <a-textarea
              v-model="addNumForm.remarks"
              :auto-size="{ minRows: 2, maxRows: 4 }"
              placeholder="请输入(选填,最多输入100个字符)"
              :max-length="100"
            />
          </a-form-model-item>
        </a-form-model>
      </a-spin>
    </a-modal>
    <a-modal
      title="库存记录"
      :visible="stockHistoryVisible"
      :width="820"
      @cancel="stockHistoryVisible=false"
    >
      <a-form-model layout="inline">
        <a-form-model-item label="日期">
          <a-range-picker @change="changeStockSearchDate" />
        </a-form-model-item>
        <a-form-model-item>
          <a-checkbox-group v-model="stockType">
            <a-checkbox :value="1">入库</a-checkbox>
            <a-checkbox :value="2">销售</a-checkbox>
            <a-checkbox :value="3">销售退回</a-checkbox>
          </a-checkbox-group>
        </a-form-model-item>
      </a-form-model>
      <a-table
        :columns="columnsStockHistory"
        :data-source="dataStockHistory"
        class="user_management_table"
        style="margin-top:10px;border:1px solid #e8e8e8;"
        :scroll="{ y: 440 }"
        :pagination="false"
        :loading="stockLoading"
      ></a-table>
    </a-modal>
  </a-card>
</template>

<script>
import moment from 'moment'
import { STable, Ellipsis } from '@/components'
import courseModel from '@/components/course'
import CreateForm from '../../list/modules/CreateForm'
import { itemList, changeItemType, itemDel, itemCreate, itemEdit, itemAddNum, itemStockList } from '@/api/courseCharge'
export default {
  name: 'TableList',
  components: {
    STable,
    Ellipsis,
    CreateForm,
    courseModel,
    // StepByStepModal
  },
  data() {
    return {
      store_user: null,
      mdl: {},
      visibles: false,
      visiblesEdit: false,
      ruleForm: {
        name: '',
        unit_price: '',
        remark: '',
        stock: '',
        course_arr: [],
        type: 0,
      },
      ruleFormEdit: {
        name: '',
        unit_price: '',
        remark: '',
        stock: '',
        course_arr: [],
        type: null,
      },
      rules: {
        name: [{ required: true, message: '请输入费用名称 ' }],
        unit_price: [{ required: true, message: '请输入售卖单价', trigger: 'blur' }],
        stock: [{ required: true, message: '请输入库存预警数量', trigger: 'blur' }],
      },
      layout: {
        labelCol: { span: 5 },
        wrapperCol: { span: 18 },
      },
      confirmLoading: false,
      // 高级搜索 展开/关闭
      advanced: false,
      // 查询参数
      keywords: '',
      isStock: false,
      queryParam: {
        school_id: this.$store.state.user.school,
        stock: null,
        is_enable: null,
      },
      pagination:{
        showTotal:total=>`共${total}条数据`,
      },
      // 表头
      columns: [
        {
          title: '物品名称',
          dataIndex: 'name',
          width: 200,
          fixed: 'left',
        },
        {
          title: '售卖单价',
          dataIndex: 'unit_price',
          customRender(unit_price) {
            return '￥' + unit_price
          },
        },
        {
          title: '剩余库存数',
          dataIndex: 'surplus_stock',
          scopedSlots: { customRender: 'stock' },
        },
        {
          title: '绑定课程',
          dataIndex: 'course_arr',
          ellipsis: true,
          scopedSlots: { customRender: 'course' },
        },
        {
          title: '启用状态',
          dataIndex: 'is_enable',
          align: 'center',
          scopedSlots: { customRender: 'is_enable' },
        },
        {
          title: '操作',
          //   width: '100px',
          dataIndex: 'action',
          fixed: 'right',
          align: 'right',
          ellipsis: true,
          scopedSlots: { customRender: 'action' },
        },
      ],
      // 加载数据方法 必须为 Promise 对象
      loadData: (parameter) => {
        return itemList(Object.assign(parameter, this.queryParam, { keywords: this.keywords })).then((res) => {
          return res
        })
      },
      storageData: null,
      sendChildData: [],
      //添加库存弹框
      addNumLoading: false,
      addNumVisible: false,
      addNumForm: {
        goods_id: null,
        operator: null,
        purchase_at: moment(), //采购时间
        type: 1, //1入库，2销售，3销售退回
        unit_price: undefined,
        total_price: 0, //总价
        number: null,
        remarks: '', //备注1
        goods_name: '', //物品1
        school_id: this.$store.state.user.school,
      },
      addNumRule: {
        total_price: [{ required: true, message: '请输入售卖总价 ', trigger: 'blur' }],
        unit_price: [{ required: true, message: '请输入售卖单价', trigger: 'blur' }],
        number: [{ required: true, message: '请输入采购数量', trigger: 'blur' }],
        operator: [{ required: true, message: '请输入采购人 ', trigger: 'blur' }],
        purchase_at: [{ required: true, message: '请选择采购日期 ', trigger: 'change' }],
      },
      //库存记录
      stockHistoryVisible: false,
      columnsStockHistory: [
        {
          title: '日期',
          dataIndex: 'created_at',
          fixed: 'left',
          align: 'center',
        },
        {
          title: '经办人',
          dataIndex: 'operator',
          align: 'center',
        },
        {
          title: '类型',
          dataIndex: 'type',
          align: 'center',
          customRender(type) {
            return type == 1 ? '入库' : type == 2 ? '销售' : type == 3 ? '销售撤回' : '--'
          },
        },
        {
          title: '数量',
          dataIndex: 'number',
          ellipsis: true,
        },
        {
          title: '出入库单价',
          dataIndex: 'unit_price',
          customRender(unit_price) {
            return '￥' + unit_price
          },
        },
        {
          title: '出入库总价',
          dataIndex: 'total_price',
          ellipsis: true,
          customRender(total_price) {
            return '￥' + total_price
          },
        },
        {
          title: '备注',
          dataIndex: 'remarks',
          ellipsis: true,
          customRender(text) {
            return text || '-'
          },
        },
      ],
      dataStockHistory: [],
      stockStartTime: '',
      stockEndTime: '',
      stockType: undefined,
      nowShowStock: undefined,
      stockLoading: false,
      openChecked: false,
      closeChecked: false,
    }
  },
  created() {
    if (this.$route.query.no_stock) {
      this.isStock = true
      this.queryParam.stock = 1
    }
    this.store_user = this.$store.state.user
  },
  watch: {
    addNumVisible(val) {
      if (val == false) {
        this.addNumForm = {
          goods_id: null,
          operator: null,
          purchase_at: moment(), //采购时间
          type: 1, //1入库，2销售，3销售退回
          unit_price: '',
          total_price: '', //总价
          number: null,
          remarks: '', //备注1
          goods_name: '', //物品1
          school_id: this.$store.state.user.school,
        }
      }
    },
    stockHistoryVisible(val) {
      if (val == false) {
        this.dataStockHistory = []
        this.stockStartTime = ''
        this.stockEndTime = ''
        this.stockType = undefined
        this.nowShowStock = undefined
      }
    },
    stockStartTime(val) {
      if (this.nowShowStock) {
        this.showStock(this.nowShowStock)
      }
    },
    stockEndTime(val) {
      if (this.nowShowStock) {
        this.showStock(this.nowShowStock)
      }
    },
    stockType(val) {
      if (this.nowShowStock) {
        this.showStock(this.nowShowStock)
      }
    },
    queryParam: {
      handler(val) {
        this.$refs.table.refresh()
      },
      immediate: false,
      deep: true,
    },
    addNumForm: {
      handler(val) {
        if (val.unit_price) {
          if (val.number) {
            let uPrice = +Number(val.unit_price)
            let Num = +Number(val.number)
            val.total_price = uPrice * Num >= 0 ? this.accMul(uPrice, Num) : 0
          } else {
            val.total_price = 0
          }
        } else {
          val.total_price = 0
        }
        // this.$refs.table.refresh()
      },
      immediate: false,
      deep: true,
    },
  },
  methods: {
    countForm(type) {
      if(type=='num'||type=='unit'){
        if (this.addNumForm.unit_price) {
          this.addNumForm.total_price = this.accMul(this.addNumForm.unit_price,this.addNumForm.number)
        }else{
           this.addNumForm.total_price=0
        }
      }else if(type=='total'){
        if(this.addNumForm.number){
          this.addNumForm.unit_price = this.accMul1(this.addNumForm.total_price,this.addNumForm.number)
        }
      }
    },
    accMul(arg1, arg2) {
      let m = 0
      let s1 = arg1.toString()
      let s2 = arg2.toString()
      try {
        m += s1.split('.')[1].length
      } catch (e) {}
      try {
        m += s2.split('.')[1].length
      } catch (e) {}
      return (Number(s1.replace('.', '')) * Number(s2.replace('.', ''))) / Math.pow(10, m)
    },
    accMul1(arg1, arg2) {
      let m = 0
      let s1 = arg1.toString()
      let s2 = arg2.toString()
      try {
        m += s1.split('.')[1].length
      } catch (e) {}
      try {
        m += s2.split('.')[1].length
      } catch (e) {}
      return Number(s1.replace('.', '')) / Number(s2.replace('.', '')) / Math.pow(10, m)
    },
    showAddNumModel(e) {
      this.addNumForm.goods_id = e.id
      this.addNumForm.goods_name = e.name
      this.addNumForm.operator = this.$store.state.user.name //经办人1
      this.addNumForm.unit_price = e.unit_price
      this.addNumVisible = true
    },
    addNumSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.addNumLoading = true
          let params = JSON.parse(JSON.stringify(this.addNumForm))
          params.purchase_at = moment(this.addNumForm.purchase_at).format('YYYY-MM-DD')
          itemAddNum(params)
            .then((res) => {
              this.$refs.table.refresh()
              this.addNumLoading = false
              this.$message.success('增加库存数据成功')
              this.addNumVisible = false
            })
            .catch((err) => {
              this.$message.error(err.data.message || '增加库存数据失败，请稍后重试')
            })
        } else {
          return
        }
      })
    },
    changeType(data, e) {
      if (data == 2 || data == null) {
        changeItemType({ is_enable: 1 }, e.id)
          .then((res) => {
            this.$refs.table.refresh(false)
          })
          .catch((err) => {
            this.$message.error(err.data.message || '更新状态失败')
          })
      } else {
        changeItemType({ is_enable: 2 }, e.id)
          .then((res) => {
            this.$refs.table.refresh(false)
          })
          .catch((err) => {
            this.$message.error(err.data.message || '更新状态失败')
          })
      }
    },
    del(e) {
      let that = this
      this.$confirm({
        title: '提示',
        content: '确认删除？',
        okText: '确定',
        okType: 'primary',
        cancelText: '取消',
        onOk() {
          itemDel(e.id)
            .then((res) => {
              that.$message.success('删除成功')
              that.$refs.table.refresh(false)
            })
            .catch((err) => {
              that.$message.error(err.data.message || '删除失败')
            })
        },
        onCancel() {
          console.log('Cancel')
        },
      })
    },
    modelSubmit(formName, type) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.ruleForm.type == 2 && this.ruleForm.course_arr.length == 0) {
            this.$message.error('请选择绑定课程，若您不需要绑定课程，请选择不绑定课程~')
            return
          }
          this.confirmLoading = true
          itemCreate({
            name: this.ruleForm.name,
            unit_price: this.ruleForm.unit_price,
            stock: this.ruleForm.stock,
            school_id: this.store_user.school,
            course_arr: this.ruleForm.course_arr,
            type: this.ruleForm.type,
          })
            .then((res) => {
              this.$message.success('添加成功')
              this.confirmLoading = false
              this.ruleForm = {
                name: '',
                unit_price: '',
                remark: '',
                stock: '',
                course_arr: [],
                type: 0,
              }
              if (type == 2) {
                let resdata = JSON.parse(JSON.stringify(res))
                this.showAddNumModel(resdata)
              }

              this.visibles = false
              this.$refs.table.refresh()
            })
            .catch((err) => {
              this.$message.error(err.data.message || '添加失败')
              this.confirmLoading = false
            })
        } else {
          return
        }
      })
    },
    modelCancel() {
      //model
      this.visibles = false
    },
    modelEditSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          if (this.ruleFormEdit.type == 2 && this.ruleFormEdit.course_arr.length == 0) {
            this.$message.error('请选择绑定课程，若您不需要绑定课程，请选择不绑定课程~')
            return
          }
          this.confirmLoading = true
          let data = []
          this.ruleFormEdit.course_arr.forEach((val) => {
            data.push({
              id: val.id,
              name: val.name,
            })
          })
          itemEdit(
            {
              name: this.ruleFormEdit.name,
              stock: this.ruleFormEdit.stock,
              unit_price: this.ruleFormEdit.unit_price,
              school_id: this.store_user.school,
              course_arr: data,
              type: this.ruleFormEdit.type,
            },
            this.ruleFormEdit.id
          )
            .then((res) => {
              this.$message.success('编辑成功')
              this.confirmLoading = false
              this.visiblesEdit = false
              this.$refs.table.refresh()
            })
            .catch((err) => {
              this.$message.error(err.data.message || '编辑失败')
              this.confirmLoading = false
            })
        }
      })
    },
    modelEditCancel() {
      this.visiblesEdit = false
    },
    handleEdit(record) {
      this.ruleFormEdit = JSON.parse(JSON.stringify(record))
      this.visiblesEdit = true
    },
    handleOk() {
      this.$refs.table.refresh()
    },
    showComponents(e) {
      this.storageData = e
      if (e == 'add') {
        let data = []
        this.ruleForm.course_arr.forEach((val) => {
          data.push(val.id)
        })
        this.$refs.course.showModal(data)
      } else if (e == 'edit') {
        let data = []
        this.ruleFormEdit.course_arr.forEach((val) => {
          data.push(val.id)
        })
        this.$refs.course.showModal(data)
      }
    },
    receiveData(data) {
      if (this.storageData == 'add') {
        this.ruleForm.course_arr = data
      } else if (this.storageData == 'edit') {
        this.ruleFormEdit.course_arr = data
      }
    },
    showStock(e) {
      this.stockLoading = true
      this.nowShowStock = e
      itemStockList(
        {
          school_id: this.$store.state.user.school,
          start_time: this.stockStartTime,
          end_time: this.stockEndTime,
          type: this.stockType,
          pageSize: 99999999999,
        },
        e.id
      )
        .then((res) => {
          this.stockHistoryVisible = true
          this.dataStockHistory = res.data
          this.stockLoading = false
        })
        .catch((err) => {
          this.stockLoading = false
          this.$message.error(err.data.message || '获取库存记录失败，请刷新后重试~')
        })
    },
    changeStockSearchDate(date, dateArr) {
      this.stockStartTime = dateArr[0]
      this.stockEndTime = dateArr[1]
    },
    changeSearchType(e) {
      if (e.target.checked == true) {
        this.queryParam.stock = 1
      } else {
        this.queryParam.stock = null
      }
    },
    openEnable(e) {
      if (e.target.checked == true) {
        this.closeChecked = false
        this.queryParam.is_enable = 1
        this.openChecked = true
      } else {
        this.queryParam.is_enable = null
        this.openChecked = false
      }
    },
    closeEnable(e) {
      if (e.target.checked == true) {
        this.openChecked = false
        this.queryParam.is_enable = 2
        this.closeChecked = true
      } else {
        this.queryParam.is_enable = null
        this.closeChecked = false
      }
    },
  },
}
</script>
<style lang="less" scoped>
.expand_warning {
  margin: 16px 0;
  background-color: #fff0e7;
  border-radius: 4px;
}
</style>